import { configureStore, AnyAction, ThunkMiddleware } from '@reduxjs/toolkit';
import { ToolkitStore } from '@reduxjs/toolkit/dist/configureStore';
import userReducer, { IUserState } from './slices/userSlice';

/**
 * Хранилище Redux Toolkit.
 * @type {
 * ToolkitStore<{ user: IUserState; }, AnyAction, [ThunkMiddleware<{ user: IUserState; }, AnyAction>]>
 * }
 */
export const store: ToolkitStore<
    { user: IUserState; },
    AnyAction,
    [ThunkMiddleware<{ user: IUserState; }, AnyAction>]
> = configureStore({
    reducer: {
        user: userReducer,
    }
});

/**
 * @typedef { Object } RootState - Тип для состояния хранилища.
 */
export type RootState = ReturnType<typeof store.getState>;
/**
 * @typedef { Object } AppDispatch - Тип для функции-диспетчера хранилища.
 */
export type AppDispatch = typeof store.dispatch;